﻿<!---
 
  Copyright (c) 2010, Cristian Costantini - cristian@millemultimedia.it
  
  FileManager is licensed under the terms of the Open Source GPL 3.0 license. 
	
	http://www.gnu.org/licenses/gpl.html
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
--->

<cfcomponent output="false">

	<cfset variables.instance = structNew() />
	
	<cfset variables.instance.icon = arrayNew(1) />
	<cfset variables.instance.script = arrayNew(1) />
	<cfset variables.instance.handler = arrayNew(1) />
	
	<cffunction name="onPluginRegister" access="public" returntype="void">
		<cfargument name="name" type="string" required="true" hint="Plugin name" />
		<cfargument name="plugin" type="fileManager.util.AbsPlugin" required="true" hint="Plugin instance" />
		<cfargument name="pluginConfig" type="xml" required="true" hint="Plugin config" />
		
		<cfset var handler = xmlSearch( pluginConfig, "/plugin/display-objects/event/" ) />
		<cfset var import = xmlSearch( pluginConfig, "/plugin/display-objects/import/" ) />
		<cfset var param = structNew() />
 		<cfset var i = 0 />
		
		<cfif arrayLen( import )>
		
			<cfloop array="#import[1].XmlChildren#" index="i">
			
				<cfset param = structNew() />
				
				<cfif i.XmlName eq 'script'>
				
					<cfset param.src = i.XmlAttributes.src />
					
					<cfset variables.instance.script.add( param  ) />
					
				<cfelseif i.XmlName eq 'icon' >
				
					<cfparam name="i.XmlAttributes.id" default="#arguments.name#" />
					<cfparam name="i.XmlAttributes.message" default="" />
					
					<cfset param.id = i.XmlAttributes.id />
					<cfset param.src = i.XmlAttributes.src />
					<cfset param.message = i.XmlAttributes.message />
					
					<cfset variables.instance.icon.add( param  ) />
					
				</cfif>
				
				
			</cfloop>
		
		</cfif>
		
		<cfif arrayLen( handler )>
		
			<cfloop array="#handler[1].XmlChildren#" index="i">
			
				<cfparam name="i.XmlAttributes.ddGroup" default="" />
				
				<cfset param = structNew() />
				<cfset param.ddGroup = i.XmlAttributes.ddGroup />
				<cfset param.target = i.XmlAttributes.target />
				<cfset param.event = i.XmlAttributes.event />
				<cfset param.plugin = i.XmlAttributes.plugin />
			
				<cfset variables.instance.handler.add( param ) />
			
			</cfloop>
		
		</cfif>
		
	</cffunction>
	
	<cffunction name="getAll" access="public" returntype="Struct" >
		<cfreturn variables.instance/>
	</cffunction>
	
	<cffunction name="getIcon" access="public" returntype="Array" >
		<cfreturn variables.instance.icon/>
	</cffunction>
	
	<cffunction name="getScript" access="public" returntype="Array" >
		<cfreturn variables.instance.script/>
	</cffunction>
	
	<cffunction name="getHandler" access="public" returntype="Array" >
		<cfreturn variables.instance.handler/>
	</cffunction>

</cfcomponent>